package com.zklh.leetcode.top100;

import java.util.Arrays;

/**
 * 轮转数组算法实现
 *
 * @version 1.0
 * @Author tongnan
 * @Date 2023/10/9
 */
public class Solution189 {
    public void rotate(int[] nums, int k) {
        k = k % nums.length;
        int[] cache = Arrays.copyOfRange(nums, nums.length-k, nums.length);

        for (int i = nums.length-k-1; i >= 0; i--) {
            nums[i+k] = nums[i];
        }

        for (int i = 0; i < k; i++) {
            nums[i] = cache[i];
        }
    }
}